#pragma once

#include "Server/WorkerRunner.h"
#include "wch/Mutex.h"
#include "DBMsgHandler.h"

using namespace wch;

class DBExecutor;
class DBWorker
	: public WorkerRunner<DBMsgHandler>
{
public:
	DBWorker(UInt8);
	~DBWorker();

public:
	inline UInt8 tid() const { return _tid; }

public:
	void PushObjectUpdateData(const char *, ...);
	void PushPlatUpdateData(const char *, ...);

private:
	bool DoOjbectQuery(const char* query);
	bool DoPlatQuery(const char * query);

protected:
	bool init();
	bool postInit();
	void unInit();
	void onTimer();
	void onPause();
	std::string getLogName();

private:
	UInt8	_tid;

private:
	std::unique_ptr<DBExecutor> m_ObjectExecutor;
	FastMutex m_ObjectMutex;
	std::vector<const char *> m_ObjectUpdateItems;

private:
	std::unique_ptr<DBExecutor> m_PlatExecutor;
	FastMutex m_PlatMutex;
	std::vector<const char *> m_PlatUpdateItems;
};
